package org.jing.core.thread;

import org.jing.core.thread.itf.BaseMultiplyThread;

/**
 * Description: <br>
 *
 * @author bks <br>
 * @since 2023-09-19 <br>
 */
public class ThreadDispatcher extends Thread {
    private final BaseMultiplyThread thread;

    private final boolean wait;

    ThreadDispatcher(BaseMultiplyThread thread, boolean wait) {
        this.thread = thread;
        this.wait = wait;
    }

    @Override protected void finalize() throws Throwable {
        ThreadFactory.remove(this);
        super.finalize();
    }

    boolean canWait() {
        return wait;
    }

    @Override public void run() {
        thread.before();

        thread.execute();

        thread.after();

        ThreadFactory.remove(this);
    }
}
